package tests
{
	import flexunit.framework.TestCase;
	import flexunit.framework.TestSuite;
	import model.Piece;
	import model.moving.NormalMove;
	import model.moving.NoMove;
	import model.moving.Slashing;
	import model.moving.Quickness;
	import model.moving.Charging;
	import model.attack.Defuse;
	import model.attack.NormalAttack;
	
	public class PieceTest extends TestCase
	{
		public function PieceTest(methodName:String){
			super(methodName);
		}
		
		public static function suite():TestSuite{
			var ts:TestSuite = new TestSuite();
			
			ts.addTest(new PieceTest("testPiece"));
			ts.addTest(new PieceTest("testAttack"));
			ts.addTest(new PieceTest("testNormalMove"));
			ts.addTest(new PieceTest("testNoMove"));
			ts.addTest(new PieceTest("testSlashing"));
			ts.addTest(new PieceTest("testQuickness"));
			ts.addTest(new PieceTest("testCharging"));
			ts.addTest(new PieceTest("testDefuse"));
			
			return ts;
		}
		
		public function testPiece():void{
			var name:String = "Droid";
			var power:Number = 9;
			var testPiece:Piece = new Piece("Droid", 9,'',new NormalMove());
			
			assertTrue("Expecting True: ", name == testPiece.getName());
			assertTrue("Expecting True: ", power == testPiece.getPower());
		}
		
		public function testAttack():void{
			var attacker:Piece = new Piece("Droid", 2, '',new NormalMove());
			var defender:Piece = new Piece("Luke", 9, '', new NormalMove());
			var third:Piece = new Piece("Vader", 9, '', new NormalMove());
			
			var winner:Piece = attacker.attack(defender);
			var newFight:Piece = defender.attack(third);
			
			assertTrue("Expecting True: ", winner.toString() == defender.toString());
			assertFalse("Expecting False: ", winner.toString() == attacker.toString());
		}
		
		public function testNormalMove():void{
			var piece1:Piece = new Piece("Jabba",5,"images/jabba.jpg",new NormalMove());
			piece1.setXY(3,3);
			assertFalse("Expecting False: ", piece1.move(2,2));
			assertTrue("Expecting True: ", piece1.move(3,2));
			assertFalse("Expecting False: ", piece1.move(3,5));
			assertTrue("Expecting True: ", piece1.move(2,3));
		}
		
		public function testNoMove():void{
			var piece2:Piece = new Piece('Bomb', 11, 'images/bomb.jpg', new NoMove());
			piece2.setXY(4,4);
			assertFalse("Expecting False: ", piece2.move(4,5));
		}
		
		public function testSlashing():void{
			var piece3:Piece = new Piece('Anakin', 7, 'images/anakin.jpg', new Slashing());
			piece3.setXY(0,0);
			assertTrue("Expecting True: ", piece3.move(4,4));
			assertFalse("Expecting False: ", piece3.move(4,5));
			
			piece3.setXY(2,4);
			assertTrue("Expecting True: ", piece3.move(1,3));
			assertTrue("Expecting True: ", piece3.move(2,5));
		}
		
		public function testQuickness():void{
			var piece4:Piece = new Piece('Chewy',7,'images/chewy.jpg', new Quickness());
			piece4.setXY(3,3);
			assertTrue("Expecting True: ", piece4.move(4,4));
			assertFalse("Expecting False: ", piece4.move(5,5));
			
			piece4.setXY(5,6);
			assertTrue("Expecting True: ", piece4.move(4,5));
			assertTrue("Expecting True: ", piece4.move(6,6));
		}
		
		public function testCharging():void{
			var piece5:Piece = new Piece("Dooku",8,'images/dooku.jpg', new Charging());
			piece5.setXY(6,4);
			assertTrue("Expecting True: ", piece5.move(6,10));
			assertFalse("Expecting False: ", piece5.move(5,6));
			
			assertTrue("Expecting True: ", piece5.move(6,5));
		}
		
		public function testDefuse():void{
			var piece6:Piece = new Piece('bomb',11,'images/bomb.jpg',new NoMove());
			var piece7:Piece = new Piece('r2', 3,'images/r2.jpg',new NormalMove(),new Defuse());
			var piece8:Piece = new Piece();
			var piece9:Piece = new Piece('some droid',4,'images/bdoid.jpg',new NormalMove(), new NormalAttack());
			
			assertTrue("Expecting True: ", piece7.attack(piece6) == piece7);
			assertTrue("Expecting True: ", piece7.attack(piece8) == piece7);
			assertFalse("Expecting False: ", piece7.attack(piece9) == piece7);
		}
	}
}